package com.ronghui.cash.config;

import com.ronghui.cash.interceptor.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
	@Bean
	public HandlerInterceptor getCheckAccessTokenInterceptor() {
		return new CheckAccessTokenInterceptor();
	}

	@Bean
	public HandlerInterceptor getCheckAuthRejectInterceptor() {
		return new CheckAuthRejectInterceptor();
	}

	@Bean
	public HandlerInterceptor getCheckAuthInterceptor() {
		return new CheckAuthInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 注册拦截器
		InterceptorRegistration ir = registry.addInterceptor(getCheckAccessTokenInterceptor());
		// 配置拦截的路径
		ir.addPathPatterns("/user/**");
		ir.addPathPatterns("/order/**");
		ir.addPathPatterns("/auth/**");
		ir.addPathPatterns("/returnMoney/**");
		// ir.addPathPatterns("/transaction/**");
		// 配置不拦截的路径
		//ir.excludePathPatterns("/auth/limuStatus");

		/**
		 *  黑名单拦截
		 * 1、基础认证阶段：直接拒绝
		 */
		//registry.addInterceptor(getCheckBlackUserInterceptor()).addPathPatterns("/auth/**").excludePathPatterns("/auth/limuStatus");

		/*
		 *  黑名单拦截
		 * 2、分期阶段：直接拒绝
		 *
		 *  灰名单拦截
		 * 1、分期申请流程：如果归属地不在广东省的，必须要完成运营商、电商认证其中一项，否则不允许分期
		 * 2、客服在审核阶段要了解他通话记录情况、电商消费情况
		 */
		/*registry.addInterceptor(getCheckBlackAndGreyUserInterceptor())
				.addPathPatterns("/order/create")
				.addPathPatterns("/order/getApplyFenqiInfo")
				.addPathPatterns("/order/confirmContractInfo")
				.addPathPatterns("/order/confirmFenqi")

				.addPathPatterns("/order/create.json")
				.addPathPatterns("/order/getApplyFenqiInfo.json")
				.addPathPatterns("/order/confirmContractInfo.json")
				.addPathPatterns("/order/confirmFenqi.json")
				.excludePathPatterns("/auth/limuStatus");*/

		// 403 未认证的
		registry.addInterceptor(getCheckAuthInterceptor()).addPathPatterns("/auth/more/**")
				.addPathPatterns("/order/create")
				.addPathPatterns("/order/getApplyFenqiInfo")
				.addPathPatterns("/order/confirmContractInfo")
				.addPathPatterns("/order/confirmFenqi")
				.addPathPatterns("/user/modifyIdentityPic")

				.addPathPatterns("/order/create.json")
				.addPathPatterns("/order/getApplyFenqiInfo.json")
				.addPathPatterns("/order/confirmContractInfo.json")
				.addPathPatterns("/order/confirmFenqi.json")
				.addPathPatterns("/user/modifyIdentityPic.json")
				;


	}
}
